<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="com.neiquan.backstage.pub.bsc.dao.po.User"%>
<%@page import="com.neiquan.backstage.user.UserService"%>
<%@page import="java.util.List"%>
<%@page import="com.neiquan.backstage.common.CommonService"%>
<%@page import="com.neiquan.backstage.common.util.SpringContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
ApplicationContext appCtx = SpringContextUtils.getApplicationContext();
String userId=request.getParameter("id");
int id=Integer.parseInt(userId);
UserService userService = appCtx.getBean(UserService.class);
User user = userService.queryById(id);
pageContext.setAttribute("user", user);
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="UTF-8">
	<title>员工详情</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1.0" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/main.css" />
	</head>
	<body bgcolor="#f0f0f0" id="app" ng-app="app" ng-controller="ctrl">
		<section class="mt activesignup">
			<section class="tc">
				<form id="employeeform" class="fom">
					<section class="common_bg">
						<section class="perfect pd">
							<p class="form-inpt-p">
								<label>姓名</label><input class="inpt" id="name" value='<%=user.getName() %>' form="employeeform" ng-model="name" type="text" placeholder="请输入您的真实姓名" />
							</p>
							<input type="hidden" value='<%=user.getId() %>' name="userId">
							<!-- 
							<p class="form-inpt-p">
								<label>手机号</label><input class="inpt" value='<%=user.getPhone() %>' form="employeeform" name="phone" type="tel" pattern="((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)" placeholder="请输入您的手机号码" />
							</p>
							 -->
						</section>
					</section>
					<section class="common_bg mt">
						<section class="perfect pd">
							<p class="form-inpt-p">
								<label>部门</label><input class="inpt" value='<%=user.getDepartment() %>' form="employeeform" ng-model="department" type="text" placeholder="请输入您的所在部门" />
							</p>
							<p class="form-inpt-p">
								<label>职位</label><input class="inpt"  value='${pageScope.user.post}' form="employeeform" ng-model="post" type="text" placeholder="请输入您的职位" />
							</p>
							<p class="form-inpt-p">
								<label>密码</label><input id="password" class="inpt pwd" form="employeeform" value='<%=user.getPassword() %>' ng-model="password" type="password"  placeholder="6-20个数字或者字母" />
								<input class="btn" type="button" value="重置密码"  onclick="resetPassword()" style="letter-spacing: 0.2rem;"/>
							</p>
							<p class="form-inpt-p">
								<label>重置的密码为该用户名字全拼</label>
							</p>
						</section>
					</section>
					<button class="btn fom-submit" type="submit" style="letter-spacing: 0.2rem;" ng-click="submit()">确定</button>
				</form>
			</section>
		</section>
	</body>
	<script src="js/jquery.min.js"></script>
	<script src="angular-1.5.0-rc.2/angular.js"></script>
	<script src="js/main.js"></script>
	<script src="js/responsive.js"></script>
	<script src="js/codeZN.js"></script>
	<script type="text/javascript">
		 var resetPassword=function(){
			 if(window.confirm('你确定要重置密码吗？')){
				var b=$('#name').val();
				var password=ConvertPinyin(b);
				var password1=password.toLowerCase();
				$('#password').val(password1);
				} 
			} 
	</script>
	<script>
	var app = angular.module("app", []);
	app.controller('ctrl', function($scope, $http, $httpParamSerializer, $injector, $window) {
		$scope.userId = '${pageScope.user.userId}';
		$scope.name = '${pageScope.user.name}';
		$scope.department = '${pageScope.user.department}';
		$scope.post = '${pageScope.user.post}';
		$scope.password = '${pageScope.user.password}';
	$scope.submit = function(){
		var reqDate = jQuery.param({
			"userId": $scope.userId,
			"name": $scope.name,
			"department": $scope.department,
			"post": $scope.post,
			"password": $scope.password
		});
		var reqConfig = { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} };
		$http.post(
			"api/user/edit", reqDate,reqConfig
		).success(function(data, status) {
			if (data.code != 0) {
				alert(data.errorMessage);
				return;
			} 
			alert("修改成功");
			$window.location.href = "employeemanager.jsp";
		}).error(function(data, status) {
			alert("网络错误"+status);;
		});
	};
	});
	</script>
</html>
